package com.ykt.mall.ctrl;

import org.apache.log4j.Logger;

import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Model;
import com.ykt.interceptor.Seach;
import com.ykt.model.Customer;
import com.ykt.model.FrontOrder;
import com.ykt.model.Shop;

@ControllerBind(controllerKey="/frontOrder")
public class FrontOrderCtrl extends AdminBaseCtrl<FrontOrder>{
	private static final Logger log = Logger.getLogger(FrontOrderCtrl.class);
	public FrontOrderCtrl() {
		super(FrontOrder.class);
	}
	@Override
	protected void otherSave(Model<FrontOrder> m) {
		// TODO Auto-generated method stub
		Customer customer= Customer.dao.getCustomer(m.getStr("customer_name"), m.getStr("customer_phone"));
		if(customer==null){
			log.info("找不到用户 新增用户信息");
			customer=new Customer();
			customer.set("username", m.getStr("customer_name"))
			.set("realname", m.getStr("customer_name"))
			.set("phone", m.getStr("customer_phone")).save();
		}
		m.set("customer_id", customer.get("id"));
	}
	@Override
	protected void otherSeach(Seach seach) {
		// TODO Auto-generated method stub
		if(getCurrentUser().getInt("id")!=1){
			Integer shopId= getCurrentUser().getInt("shop_id");
			Shop shop = Shop.dao.findById(shopId);
			String shopName= shop.getStr("name");
			seach.setSqlWhere( seach.getSqlWhere()+" and  shop_name = ('"+shopName+"')");
		}
	}
	
	
}
